# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html.
# For more examples on how to use CMake, see https://github.com/android/ndk-samples.

# Sets the minimum CMake version required for this project.
cmake_minimum_required(VERSION 3.22.1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
# Since this is the top level CMakeLists.txt, the project name is also accessible
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
# build script scope).
project("videoedit")
message(${CMAKE_SOURCE_DIR})
set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -L${CMAKE_SOURCE_DIR}/libs/${CMAKE_ANDROID_ARCH_ABI}")
link_directories(${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI})

add_subdirectory(3third/glm)
add_subdirectory(3third/soundtouch)
add_subdirectory(SDL)
include_directories(spdlog/include include 3third/glm
        render  render/video
        util/message posterizetime 3third/soundtouch/include 3third/soundTouch/SoundTouch
        util)
aux_source_directory(3third/soundtouch/SoundTouch SoundSource)
if (ANDROID)
    add_definitions(-DPLATFORM=1)
    include_directories(os/android/util)
endif ()

file(GLOB file posterizetime/*.cc
        render/video/*.cc
        util/*.cc util/*.cpp util/message/*.cpp util/message/*.cc )
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
#
# In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define
# the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME}
# is preferred for the same purpose.
#
# In order to load a library into your app from Java/Kotlin, you must call
# System.loadLibrary() and pass the name of the library defined here;
# for GameActivity/NativeActivity derived applications, the same library name must be
# used in the AndroidManifest.xml file.
add_library(${CMAKE_PROJECT_NAME} SHARED ${file} ${SoundSource}
    # List C/C++ source files with relative paths to this CMakeLists.txt.
    native-lib.cpp)
if(NOT TARGET SDL3::SDL3)
    find_package(SDL3 CONFIG)
endif()

if(NOT TARGET SDL3::SDL3)
    message("NOT TARGET SDL3::SDL3")
    find_library(SDL3_LIBRARY NAMES "SDL3")
    find_path(SDL3_INCLUDE_DIR NAMES "SDL3/SDL.h")
    add_library(SDL3::SDL3 UNKNOWN IMPORTED)
    set_property(TARGET SDL3::SDL3 PROPERTY IMPORTED_LOCATION "${SDL3_LIBRARY}")
    set_property(TARGET SDL3::SDL3 PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${SDL3_INCLUDE_DIR}")
endif()

if(NOT TARGET SDL3::SDL3)
    message(FATAL_ERROR "Cannot find SDL3.

Possible ways to fix this:
- Use a SDL3 Android aar archive, and configure gradle to use it: prefab is required.
- Add add_subdirectory(path/to/SDL) to your CMake script, and make sure a vendored SDL is present there.
")
endif()
#add_executable(example_header_only example.cpp)
#target_link_libraries(example_header_only PRIVATE )
# Specifies libraries CMake should link to your target library. You
# can link libraries from various origins, such as libraries defined in this
# build script, prebuilt third-party libraries, or Android system libraries.
target_link_libraries(${CMAKE_PROJECT_NAME}
    # List libraries link to the target library

#        SDL3::SDL3
        mediandk
        android
        avcodec
        avfilter
        avformat
        avutil
        swresample
        swscale
        EGL
        GLESv3
        OpenSLES
        log)